package com.itheima;

import java.util.ArrayList;
import java.util.Scanner;

public class FindBookAuthor {

    //通过作者来查看书籍
    public void findAllBookAuthor(ArrayList<Book> list) {
        //获取要查询的作者
        System.out.println("请输入您要查询的作者");
        Scanner sc = new Scanner(System.in);
        String author = sc.next();
        //判断作者是否存在
        boolean exists = isExists(list, author);
        //书籍存在和不存在的操作
        if (!exists) {
            System.out.println("您查询的作者不存在");
        } else {
            for (Book book : list) {
                if (author.equals(book.getBookAuthor())) {
                    String bookId = book.getBookId();
                    FindBookName findBookName = new FindBookName();
                    findBookName.readBook(bookId);
                }
            }
        }
    }

    //判断作者是否存在
    public boolean isExists(ArrayList<Book> list, String author) {
        boolean flag = false;
        for (Book book : list) {
            String bookAuthor = book.getBookAuthor();

            if (book != null && author.equals(bookAuthor)) {
                flag = true;
            }
        }
        return flag;
    }

}



